<template>
    <div id="parts">
        <div class="operation">
            <el-button v-if="menuId==='4559'" @click="insertList" class="slot-btn-top" type="primary" size="small">发放任务</el-button>
             <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
            <el-form :inline="true" :model="search">
                <el-form-item label="bom名称" >
                    <!-- <el-input placeholder="请输入bom名称" v-model="search.bomName" class="inputSuffix"></el-input> -->
                     <el-autocomplete  class="autocomplete-row" v-model="search.bomName" :fetch-suggestions="querySearchAsync" placeholder="请输入物料名称" @select="handleSelect">
                        <template slot-scope="{ item }">
                                <div class="name" :title="item.value">{{ item.value }}</div>
                                <div class="addr" :title="item.type">{{ item.type }}</div>
                            </template>
                    </el-autocomplete>
                </el-form-item>
                <el-form-item label="供应商名称">
                    <el-autocomplete  class="inputSuffix"  v-model="search.supplierName" :fetch-suggestions="searchAsyncSupplier" placeholder="请输入供应商名称" @select="changeSupplier"></el-autocomplete>
                </el-form-item>
                <el-button type="primary" @click="searchBtn" icon="el-icon-search">查询</el-button>
            </el-form>
            <el-button slot="reference" type="primary">查询</el-button>
        </el-popover>
        </div>

        <el-table :data="dataList" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="batchnums" label="物料产品批号" sortable min-width="130"></el-table-column>
            <el-table-column prop="resourcenameName" label="物料产品名称" sortable min-width="130"></el-table-column>
            <el-table-column prop="typenums" label="产品型号" sortable min-width="130"></el-table-column>
            <el-table-column prop="price" label="单价" sortable width="80"></el-table-column>
            <el-table-column prop="totals" label="总价" sortable width="100"></el-table-column>
            <el-table-column prop="businesstypeName" label="供应商" sortable min-width="160"></el-table-column>
            <el-table-column prop="taskstartorendtime" label="物料计划到货时间" sortable min-width="160"></el-table-column>
            <el-table-column prop="taskbegintime" label="物料实际到货时间" sortable min-width="160"></el-table-column>
            <el-table-column prop="actualcompletenums" label="实际量" sortable width="90"></el-table-column>
            <el-table-column prop="remainingnums" label="剩余量" sortable width="90"></el-table-column>
            <el-table-column prop="istaskend" label="是否发放完"  sortable width="60">
                <template slot-scope="scope">
                    <span :class="scope.row.istaskend==='1'?'el-icon-circle-check cl-success':''" class="icon-circle"></span>
                </template>
            </el-table-column>
            <el-table-column prop="taskendtime" label="物料实际发放完时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="taskendaddtime" label="发放完创建时间" sortable min-width="170"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                <template slot-scope="scope">
                    <el-button @click="updateList(scope.row)" type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>

        <!-- 详情信息 -->
        <el-dialog :title="dialogTitle" width="85%" top="30px" :visible.sync="isDialog" :close-on-click-modal="false" >
            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="任务信息" name="1" class="dialog1" :style="dialogHeightPane" >

                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="令号"><el-input v-model="dialogList.taskcode" :disabled="!dialogListDisabled.taskcode"></el-input></el-form-item>
                        <el-form-item label="物料产品批号"><el-input v-model="dialogList.batchnums" :disabled="!dialogListDisabled.batchnums"></el-input></el-form-item>
                        <el-form-item label="物料产品名称">
                             <el-autocomplete v-model="dialogList.resourcenameName" :fetch-suggestions="querySearchAsync" placeholder="请输入内容"  @select="handleSelect" :disabled="!dialogListDisabled.resourcenameName"></el-autocomplete>
                        </el-form-item>
                        <el-form-item label="产品型号"><el-input v-model="dialogList.typenums" :disabled="!dialogListDisabled.typenums"></el-input></el-form-item>
                        <el-form-item label="供应商">
                            <el-select v-model="dialogList.businesstypeName" :disabled="!dialogListDisabled.businesstype">
                                <el-option v-for="item in customers" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="收货计划编制人"><el-input v-model="dialogList.taskreleasepersonName" :disabled="!dialogListDisabled.taskreleasepersonName"></el-input></el-form-item>
                        <el-form-item label="编制创建时间"><el-date-picker v-model="dialogList.taskreleaseaddtime" :disabled="!dialogListDisabled.taskreleaseaddtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="物料管理负责人">
                            <el-select v-model="dialogList.taskperformpersonName" :disabled="!dialogListDisabled.taskperformperson">
                                <el-option v-for="item in materialManagers" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="物料计划到货时间">
                            <el-date-picker v-model="dialogList.taskstartorendtime" :disabled="!dialogListDisabled.taskstartorendtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="计划创建类型">
                            <el-select v-model="dialogList.tasktype" :disabled="!dialogListDisabled.tasktype">
                                <el-option label="计划任务" :value="1"></el-option>
                                <el-option label="临时任务" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>

                    <h3 class="dialog-plate-title"><span>待办信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务是否接收">
                            <el-select v-model="dialogList.istaskstart" :disabled="!dialogListDisabled.istaskstart">
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="接收创建时间">
                            <el-date-picker v-model="dialogList.taskstartaddtime" :disabled="!dialogListDisabled.taskstartaddtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                    </el-form>

                    <h3 class="dialog-plate-title"><span>进行中信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="物料是否到货">
                            <el-select v-model="dialogList.istaskbegin" :disabled="!dialogListDisabled.istaskbegin">
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="物料实际到货时间">
                            <el-date-picker v-model="dialogList.taskbegintime" :disabled="!dialogListDisabled.taskbegintime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="到货创建时间">
                            <el-date-picker v-model="dialogList.taskbeginaddtime" :disabled="!dialogListDisabled.taskbeginaddtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="计量单位">
                            <el-input  v-model="dialogList.unit" :disabled="!dialogListDisabled.unit"></el-input>
                        </el-form-item>
                        <el-form-item label="计划原料总量">
                            <el-input v-model="dialogList.tasknums" :disabled="!dialogListDisabled.tasknums"></el-input>
                        </el-form-item>
                        <el-form-item label="实际原料总量">
                            <el-input v-model="dialogList.actualcompletenums" :disabled="!dialogListDisabled.actualcompletenums"></el-input>
                        </el-form-item>
                        <el-form-item label="剩余量">
                            <el-input v-model="dialogList.remainingnums" :disabled="!dialogListDisabled.remainingnums"></el-input>
                        </el-form-item>
                        <el-form-item label="物料是否发放完">
                            <el-select v-model="dialogList.istaskend" :disabled="!dialogListDisabled.istaskend">
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="物料实际发放完时间">
                            <el-date-picker v-model="dialogList.taskendtime" :disabled="!dialogListDisabled.taskendtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="发完创建时间">
                            <el-date-picker v-model="dialogList.taskendaddtime" :disabled="!dialogListDisabled.taskendaddtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                    </el-form>

                    <h3 class="dialog-plate-title"><span>复核信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="dialogList" label-position="right" label-width="180px">
                        <el-form-item label="任务是否复核">
                            <el-select v-model="dialogList.isreviewtask" :disabled="!dialogListDisabled.isreviewtask">
                                <el-option label="否" value="0"></el-option>
                                <el-option label="是" value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="复核执行人">
                            <el-input v-model="dialogList.reviewpersonName" :disabled="!dialogListDisabled.reviewpersonName"></el-input>
                        </el-form-item>
                        <el-form-item label="复核结果">
                            <el-select v-model="dialogList.reviewresult" :disabled="!dialogListDisabled.reviewresult">
                                <el-option label="【空】" value="-1"></el-option>
                                <el-option label="正常" value="1"></el-option>
                                <el-option label="异常" value="0"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="复核时间">
                            <el-date-picker v-model="dialogList.reviewtime" :disabled="!dialogListDisabled.reviewtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="复核创建时间">
                            <el-date-picker v-model="dialogList.reviewaddtime" :disabled="!dialogListDisabled.reviewaddtime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                    </el-form>
                    <div style="text-align: right">
                        <el-button @click="submitList" type="primary">确 定</el-button>
                    </div>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'"  label="出库信息" name="2" :style="dialogHeightPane">
                    <el-button @click="insertProcessStateList('add')" type="primary" size="small">新增</el-button>
                     <el-button @click="insertProcessStateList('change')" type="primary" size="small">转库</el-button>
                    <el-table :data="processStateData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="nameName" label="物料名称" sortable min-width="160"></el-table-column>
                        <el-table-column prop="batchnums" label="物料批号" sortable min-width="120"></el-table-column>
                        <el-table-column prop="typenums" label="物料型号" sortable min-width="120"></el-table-column>
                        <el-table-column prop="code" label="物料条码" sortable min-width="160"></el-table-column>
                        <el-table-column prop="usenums" label="使用数量" sortable min-width="100"></el-table-column>
                        <el-table-column prop="usepersonName" label="领料人" sortable min-width="120"></el-table-column>
                        <el-table-column prop="outstoragetime" label="出库时间" sortable min-width="170"></el-table-column>
                        <el-table-column prop="materialstate" label="物料状态" :formatter="formatterMaterialState" sortable min-width="130"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateProcessStateList(scope.row)" type="text" size="small">编辑</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="processStateData.length"></el-pagination>
                </el-tab-pane>
                <el-tab-pane v-if="dialogType !== '1'" label="备注记录信息" name="3" :style="dialogHeightPane">
                    <el-button @click="insertNotesRecordList" type="primary" size="small">新增</el-button>
                    <el-table :data="notesRecordData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="table-index" :height="dialogTableHeight" style="width: 100%;" :header-cell-style="getRowClass">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="personName" label="填写人" sortable min-width="110"></el-table-column>
                        <el-table-column prop="type" label="类型" sortable min-width="110"></el-table-column>
                        <el-table-column prop="object" label="对象" sortable min-width="110"></el-table-column>
                        <el-table-column prop="time" label="填写时间" sortable min-width="160"></el-table-column>
                        <el-table-column prop="content" label="填写内容" sortable min-width="250"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="75">
                            <template slot-scope="scope">
                                <el-button @click="updateNotesRecordList(scope.row)" type="text" size="small">编辑</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="notesRecordData.length"></el-pagination>

                </el-tab-pane>
            </el-tabs>
        </el-dialog>

        <!-- 过程状态信息 -->
        <el-dialog :title="dialogProcessStateTitle" width="900px" center :visible.sync="isProcessStateDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogProcessStateList" label-position="right" label-width="180px">
                <el-form-item label="物料名称"><el-input v-model="dialogProcessStateList.nameName" disabled></el-input></el-form-item>
                <el-form-item label="物料条码"><el-input v-model="dialogProcessStateList.code" disabled></el-input></el-form-item>
                <el-form-item label="物料批号"><el-input v-model="dialogProcessStateList.batchnums" disabled></el-input></el-form-item>
                <el-form-item label="物料型号"><el-input v-model="dialogProcessStateList.typenums" disabled></el-input></el-form-item>
                <el-form-item label="计量单位"><el-input v-model="dialogProcessStateList.unit" :disabled="dialogProcessStateTitle==='编辑'"></el-input></el-form-item>
                <el-form-item label="使用数量"><el-input v-model="dialogProcessStateList.usenums" :disabled="dialogProcessStateTitle==='编辑'" type="number" ></el-input></el-form-item>
                <el-form-item label="领料人"><el-input v-model="dialogProcessStateList.usepersonName" disabled></el-input></el-form-item>
                <el-form-item label="出库时间">
                    <el-date-picker v-model="dialogProcessStateList.outstoragetime" disabled format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" style="width: 200px;"></el-date-picker>
                </el-form-item>
                <el-form-item label="出库创建时间"><el-input v-model="dialogProcessStateList.outstorageaddtime" disabled></el-input></el-form-item>
                <el-form-item label="使用机器条码"><el-input v-model="dialogProcessStateList.mcode" disabled></el-input></el-form-item>
                <el-form-item label="使用部件条码"><el-input v-model="dialogProcessStateList.pcode" disabled></el-input></el-form-item>
                <el-form-item label="物料状态" v-if="dialogProcessStateTitle!=='转库'">
                    <el-select v-model="dialogProcessStateList.materialstate">
                        <el-option label="报废" value="-1"></el-option>
                        <el-option label="返修" value="0"></el-option>
                        <el-option label="正常使用" value="1"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click="submitProcessStateList" type="primary">确 定</el-button>
            </div>

        </el-dialog>

        <!-- 备注记录信息 -->
        <el-dialog :title="dialogNotesRecordTitle" width="600px" center :visible.sync="isNotesRecordDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <el-form :inline="true" class="demo-form-inline" v-model="dialogNotesRecordList" label-position="right" label-width="180px">
                <el-form-item label="填写人"><el-input v-model="dialogNotesRecordList.personName" disabled></el-input></el-form-item>
                <el-form-item label="填写时间"><el-input v-model="dialogNotesRecordList.time" disabled></el-input></el-form-item>
                <el-form-item label="类型"><el-input v-model="dialogNotesRecordList.type"></el-input></el-form-item>
                <el-form-item label="对象"><el-input v-model="dialogNotesRecordList.object"></el-input></el-form-item>
                <el-form-item label="填写内容"><el-input type="textarea" :rows="8"  v-model="dialogNotesRecordList.content" style="width: 355px;"></el-input></el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: right;">
                <el-button @click="submitNotesRecordList" type="primary">确 定</el-button>
            </div>

        </el-dialog>


    </div>
</template>

<script>
import scybHttp from '@/axios/scybHttp.js'
import cgbHttp from '@/axios/cgbHttp.js'
    export default {
        name: "",
        data() {
            let token = sessionStorage.getItem("tokenId");
            let menuId = sessionStorage.getItem('menuId');
            let tableHeight = menuId === '4559' ? (document.documentElement.clientHeight - 170) : (document.documentElement.clientHeight - 140);

            return {
                tokenId: token,
                menuId:menuId,
                supplierAll:[],/**所有供应商 */
                pagination:{
                    currentPage:1,
                    pageSize:10,
                    total:0
                },
                search:{
                    bom:'',
                    bomName:'',
                    supplierName:'',
                    supplier:'',
                },
                currentPage:1,
                pagesize:10,
                activeName: '1',
                productName:[],
                customers:[],
                materialManagers:[],
                tableHeight: tableHeight,
                dataList: [],

                //基本信息
                isDialog: false,
                dialogTitle: '',
                dialogType:'',
                dialogHeightPane: {
                    height: (document.documentElement.clientHeight - 180) + 'px',
                    overflowY: 'auto'
                },
                dialogTableHeight: document.documentElement.clientHeight - 260,
                dialogList:{
                    actualcompletenums: "",
                    batchnums: "",
                    businesstype: "",
                    businesstypeName: "",
                    isreviewtask: "",
                    istaskbegin: "",
                    istaskend: "",
                    istaskstart: "",
                    remainingnums: "",
                    resourcename: '',
                    resourcenameName: "",
                    reviewaddtime: "",
                    reviewperson: "",
                    reviewpersonName: "",
                    reviewresult: "",
                    reviewtime: "",
                    taskbeginaddtime: "",
                    taskbegintime: "",
                    taskcode: "",
                    taskendaddtime: "",
                    taskendtime: "",
                    taskfinishstate: "",
                    tasknums: "",
                    taskperformperson: "",
                    taskperformpersonName: "",
                    taskreleaseaddtime: "",
                    taskreleaseperson: "",
                    taskreleasepersonName: "",
                    taskstartaddtime: "",
                    taskstartorendtime: "",
                    taskstate: "",
                    tasktype: "",
                    tid: "",
                    typenums: "",
                    unit: "",
                },
                dialogListDisabled:{
                    taskcode:true,
                    batchnums:true,
                    resourcename:true,
                    resourcenameName:true,
                    typenums:true,
                    businesstype:true,
                    businesstypeName:true,
                    taskreleaseperson:true,
                    taskreleasepersonName:true,
                    taskreleaseaddtime:true,
                    taskperformperson:true,
                    taskperformpersonName:true,
                    taskstartorendtime:true,
                    tasktype:true,
                    istaskstart:true,
                    taskstartaddtime:true,
                    istaskbegin:true,
                    taskbegintime:true,
                    taskbeginaddtime:true,
                    unit:true,
                    tasknums:true,
                    actualcompletenums:true,
                    remainingnums:false,
                    istaskend:true,
                    taskendtime:true,
                    taskendaddtime:true,
                    isreviewtask:true,
                    reviewperson:true,
                    reviewpersonName:true,
                    reviewresult:true,
                    reviewtime:true,
                    reviewaddtime:true,
                    taskfinishstate:true,
                    taskstate:true,
                },

                //过程状态信息
                isProcessStateDialog: false,
                dialogProcessStateTitle: '',
                dialogProcessStateList:{
                    batchnums: "",
                    code: "",
                    id: "",
                    isrepair: "",
                    materialstate: "",
                    mcode: "",
                    mid: "",
                    name: "",
                    nameName: "",
                    outstorageaddtime: "",
                    outstoragetime: "",
                    pcode: "",
                    pid: "",
                    tid: "",
                    typenums: "",
                    unit: "",
                    usenums: "",
                    useperson: "",
                    usepersonName: "",
                },
                processStateData:[],

                //备注记录信息
                dialogNotesRecordURL: {
                    getURL: '/api/adscm/operation/jqylMaterialinfo/selectByTid/',
                    insertURL: '/api/adscm/operation/jqylMaterialinfo/insert',
                    updateURL: '/api/adscm/operation/jqylMaterialinfo/update',
                },
                isNotesRecordDialog: false,
                dialogNotesRecordTitle: '',
                dialogNotesRecordList:{
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    tid: '',
                    time: '',
                    type: '',
                },
                notesRecordData:[],
            };
        },
        created() {
            let self = this;
            self.getData();
            self.getProductData();
            self.getMaterialManagersData();
            cgbHttp.supplierAllList().then(res=>{
                 res.content.forEach(element => {
                   element.value = element.name;
                });
                self.supplierAll= res.content;
            })
        },
        methods: {
            getProductData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/jqylMaterial/selectJqylMaterialGoods?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        res.data.content.forEach(element => {
                            element.value=element.bomName;
                        });
                        _this.productName = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getCustomerData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/jqylMaterial/selectJqylMaterialProvider/'+_this.dialogList.resourcename+'?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.customers = res.data.content;
                        _this.dialogList.businesstype = _this.customers.length > 0 ? _this.customers[0].id : "";
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getMaterialManagersData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/jqylMaterial/selectTaskPerformPerson?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.materialManagers = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            getData() {
                let self = this;
                let postData={
                    currentPage:self.pagination.currentPage,
                    pageSize:self.pagination.pageSize,
                    bom:self.search.bomName===''?null:self.search.bom,
                    supplier:self.search.supplierName===''?null:self.search.supplier,
                }
                switch(self.menuId){
                    case "4559":
                        postData.taskState="0";
                        postData.taskFinishState="0"
                        postData.isReviewTask="0"
                    break;
                    case "4560":
                        postData.taskState="1";
                        postData.taskFinishState="0"
                        postData.isReviewTask="0"
                    break;
                    case "4561":
                        postData.taskState="1";
                        postData.taskFinishState="1"
                        postData.isReviewTask="0"
                    break;
                    case "4562":
                         postData.taskState="1";
                        postData.taskFinishState="1"
                        postData.isReviewTask="1"
                    break;
                }
                scybHttp.materialTaskList(postData).then(res=>{
                    self.dataList = res.content.records;
                    self.pagination.total=res.content.total;
                })
            },
            searchBtn(){
                this.getData();
            },
            insertList(){
                this.isDialog = true;
                this.dialogType='1';
                this.dialogListDisabled={
                    taskcode:true,
                    batchnums:false,
                    resourcename:true,
                    resourcenameName:true,
                    typenums:true,
                    businesstype:true,
                    businesstypeName:true,
                    taskreleaseperson:false,
                    taskreleasepersonName:false,
                    taskreleaseaddtime:false,
                    taskperformperson:true,
                    taskperformpersonName:true,
                    taskstartorendtime:true,
                    tasktype:true,
                    istaskstart:false,
                    taskstartaddtime:false,
                    istaskbegin:false,
                    taskbegintime:false,
                    taskbeginaddtime:false,
                    unit:true,
                    tasknums:true,
                    actualcompletenums:false,
                    remainingnums:false,
                    istaskend:false,
                    taskendtime:false,
                    taskendaddtime:false,
                    isreviewtask:false,
                    reviewperson:false,
                    reviewpersonName:false,
                    reviewresult:false,
                    reviewtime:false,
                    reviewaddtime:false,
                    taskfinishstate:false,
                    taskstate:false,
                };
                this.dialogList={
                    actualcompletenums: "",
                    batchnums: "",
                    businesstype: "",
                    businesstypeName: "",
                    isreviewtask: "",
                    istaskbegin: "",
                    istaskend: "",
                    istaskstart: "",
                    remainingnums: "",
                    resourcename: '',
                    resourcenameName: "",
                    reviewaddtime: "",
                    reviewperson: "",
                    reviewpersonName: "",
                    reviewresult: "",
                    reviewtime: "",
                    taskbeginaddtime: "",
                    taskbegintime: "",
                    taskcode: "",
                    taskendaddtime: "",
                    taskendtime: "",
                    taskfinishstate: "",
                    tasknums: "",
                    taskperformperson: "",
                    taskperformpersonName: "",
                    taskreleaseaddtime: "",
                    taskreleaseperson: "",
                    taskreleasepersonName: "",
                    taskstartaddtime: "",
                    taskstartorendtime: "",
                    taskstate: "",
                    tasktype: "",
                    tid: "",
                    typenums: "",
                    unit: "",
                };
            },
            updateList(row) {
                this.isDialog = true;
                this.dialogType='2';
                this.activeName = '1';
                this.dialogListDisabled={
                    taskcode:this.menuId === '4559' ?true:false,
                    batchnums: this.menuId === '4559' ? false : true,
                    resourcename:this.menuId === '4559' ? true : false,
                    resourcenameName:this.menuId === '4559' ? true : false,
                    typenums:this.menuId === '4559' ? true : false,
                    businesstype:this.menuId === '4559' ? true : false,
                    businesstypeName:this.menuId === '4559' ? true : false,
                    taskreleaseperson:false,
                    taskreleasepersonName:false,
                    taskreleaseaddtime:false,
                    taskperformperson:this.menuId === '4559' ? true : false,
                    taskperformpersonName:this.menuId === '4559' ? true : false,
                    taskstartorendtime:this.menuId === '4559' ? true : false,
                    tasktype:this.menuId === '4559' ? true : false,
                    istaskstart:this.menuId === '4559' ? true : false,
                    taskstartaddtime: false,
                    istaskbegin:this.menuId === '4560' ? true : false,
                    taskbegintime:this.menuId === '4560' ? true : false,
                    taskbeginaddtime: false,
                    unit:this.menuId === '4559' ? true : false,
                    tasknums:this.menuId === '4559' ? true : false,
                    actualcompletenums:this.menuId === '4560' ? true : false,
                    remainingnums:false,
                    istaskend:this.menuId === '4560' ? true : false,
                    taskendtime:this.menuId === '4560' ? true : false,
                    taskendaddtime: false,
                    isreviewtask:this.menuId === '4561' ? true : false,
                    reviewperson:false,
                    reviewpersonName:false,
                    reviewresult:this.menuId === '4561' ? true : false,
                    reviewtime:this.menuId === '4561' ? true : false,
                    reviewaddtime:false,
                    taskfinishstate:false,
                    taskstate:false,
                };
                this.dialogList = row;
                this.dialogList.resourcename = parseInt(this.dialogList.resourcename);
                this.dialogList.businesstype = parseInt(this.dialogList.businesstype);
                this.dialogList.taskperformperson = parseInt(this.dialogList.taskperformperson);
                this.getCustomerData();
            },
            submitList(){
                let _this = this;
                let url;
                if (_this.dialogType==='1') {
                    url = '/api/adscm/operation/jqylMaterial/insert?tokenId='+_this.tokenId;
                } else if (_this.dialogType==='2') {
                    url = '/api/adscm/operation/jqylMaterial/update?tokenId='+_this.tokenId;
                }
                _this.dialogList.taskstartorendtime = _this.timestampToTime( _this.dialogList.taskstartorendtime);
                _this.dialogList.taskbegintime = _this.timestampToTime( _this.dialogList.taskbegintime);
                _this.dialogList.taskendtime = _this.timestampToTime( _this.dialogList.taskendtime);
                _this.dialogList.reviewtime = _this.timestampToTime( _this.dialogList.reviewtime);


                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data:_this.dialogList,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                      _this.getData();
                            } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },

            //过程状态信息
            getProcessStateData() {
                let _this = this;
                this.$http({
                    url: '/api/adscm/operation/jqylMaterialdetail/selectByTid/'+_this.dialogList.tid+'?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.processStateData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertProcessStateList(type){
                let self = this;
                self.isProcessStateDialog = true;
                self.dialogProcessStateTitle = type==='add'?'添加':'转库';
                self.dialogProcessStateList={
                    batchnums:self.dialogList.batchnums,
                    code: self.dialogList.code,
                    id: null,
                    isrepair: "",
                    materialstate: "",
                    mcode: "",
                    mid: "",
                    name:self.dialogList.resourcename,
                    nameName: self.dialogList.resourcenameName,
                    outstorageaddtime: "",
                    outstoragetime: "",
                    pcode: "",
                    pid: "",
                    typenums: self.dialogList.typenums,
                    unit: self.dialogList.unit,
                    usenums: "",
                    useperson: "",
                    usepersonName: "",
                    tid: self.dialogList.tid,
                };
            },
            updateProcessStateList(row) {
                this.isProcessStateDialog = true;
                this.dialogProcessStateTitle = '编辑';
                this.dialogProcessStateList = row;
            },
            submitProcessStateList(){
                let self = this,type;
                switch(self.dialogProcessStateTitle){
                    case '添加':
                        type = 'insert';
                        break;
                    case '编辑':
                        type = 'update'
                        break;
                    case '转库':
                        type = 'jqylMaterialdetailToShylMaterial'
                        break;
                }
                let postDate={
                    id:self.dialogProcessStateList.id,
                    tid:self.dialogProcessStateList.tid,
                    usenums:self.dialogProcessStateList.usenums,
                    materialstate:self.dialogProcessStateList.materialstate
                }
                scybHttp.materialDepositRecord(type,postDate).then(res=>{
                    self.isProcessStateDialog = false;
                    self.getProcessStateData();
                    self.$message.success(`${self.dialogProcessStateTitle}成功`);
                })
            },
            //备注记录信息
            getNotesRecordData() {
                let _this = this;
                this.$http({
                    url: _this.dialogNotesRecordURL.getURL + _this.dialogList.tid + '?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.notesRecordData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            insertNotesRecordList() {
                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '添加';
                this.dialogNotesRecordList = {
                    content: '',
                    id: '',
                    object: '',
                    person: '',
                    personName: '',
                    time: '',
                    type: '',
                    tid: this.dialogList.tid,
                };
            },
            updateNotesRecordList(row) {
                this.isNotesRecordDialog = true;
                this.dialogNotesRecordTitle = '编辑';
                this.dialogNotesRecordList = row;
            },
            submitNotesRecordList() {
                let _this = this;
                let url;
                if (_this.dialogNotesRecordTitle === '添加') {
                    url = _this.dialogNotesRecordURL.insertURL + '?tokenId=' + _this.tokenId;
                } else if (_this.dialogNotesRecordTitle === '编辑') {
                    url = _this.dialogNotesRecordURL.updateURL + '?tokenId=' + _this.tokenId;
                }
                this.$http({
                    url: url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data: _this.dialogNotesRecordList,
                }).then(function (res) {
                    if (res.data.statusCode == 200) {
                        _this.isNotesRecordDialog = false;
                        if (_this.dialogNotesRecordTitle === '添加') _this.getNotesRecordData();
                            } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },

            handleClick(tab, event) {
                if(tab.name==='2'){
                    this.getProcessStateData();
                } else if(tab.name==='3'){
                    this.getNotesRecordData();
                }

            },
            handleSizeChange: function (size) {
                this.pagination.pageSize = size;
                this.getData();
            },
            handleCurrentChange: function (currentPage) {
                this.pagination.currentPage = currentPage;
                this.getData();
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    return timestamp ? Y + M + D + h + m + '00' : '';
                } else {
                    return '';
                }
            },
        querySearchAsync(queryString, cb){
            let self=this;
            var results = queryString ?  self.productName.filter(self.createStateFilter(queryString)) :  self.productName;
            cb(results);
        },
        createStateFilter(queryString) {
            return (state) => {
            console.log(state.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1)
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
            }
        },
        handleSelect(item){
            let self= this;
            self.dialogList.resourcename=item.id;
        },
         searchAsyncSupplier(queryString, callback){
            let results = queryString ?  this.supplierAll.filter(this.createStateFilter(queryString)) : this.supplierAll;
            callback(results);
        },
        changeSupplier(item){
            this.search.supplier = item.id;
            this.search.supplierName = item.value;
        },
        createStateFilter(queryString) {
            return (state) => {
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) !==-1);
            };
        },
        querySearchAsync(queryString, callback){
        let result=[];
            cgbHttp.searchMaterialKeyWord({name:queryString}).then(res=>{
                if(res.content&&res.content.length>0){
                    res.content.forEach(element => {
                        element.value = element.name;
                    });
                }
                result = res.content;
                callback(result);
            })
        },
        handleSelect(item){
            let self = this;
            self.search.bom = item.id;
        },
        }
    }
</script>

<style scoped>
    .name{
        line-height: 1.6;
    }
    .addr{
        font-size: 12px;
        color:#ccc;
        line-height: 1;
    }
    #parts .el-table--small {
        font-size: 13px;
    }

    #parts .el-table .cell,
    #parts .el-table th div {
        padding-left: 0;
        padding-right: 0;
    }

    #parts .el-tab-pane.dialog1 .el-form{
        margin-bottom: 30px;
    }

</style>
